package z.explorer.ui.component.walker;

import java.awt.BorderLayout;
import java.util.List;

import javax.swing.JPanel;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import z.explorer.Main;
import z.explorer.core.storage.ExeLog;
import z.explorer.core.storage.OperationDetail;
import z.explorer.core.storage.dao.ExeLogDAO;
import z.explorer.core.storage.dao.OperationDetailDAO;
import z.explorer.ui.common.Handler;
import z.explorer.ui.common.ZTablePanel;

public class History extends JPanel implements Handler {
	private static Log log = LogFactory.getLog(History.class);
	
	private int table_id = -1;

	private ZTablePanel zTablePanel = new ZTablePanel(null);
	
	public History(){}
	
	public History(int tid){
		table_id = tid;
		loadData();
		initUI();
	}
	
	public void initUI() {
		setLayout(new BorderLayout());
		add(zTablePanel,BorderLayout.CENTER);
	}
	
	public void loadData() {
		if(table_id==-1)
		{
			zTablePanel.reloadData(null);
			return;
		}
		
		log.info("start to load execution log information for table ...");
		ExeLogDAO exeLogDao = (ExeLogDAO) Main.context
				.getBean("exeLogDAO");
		List<ExeLog> list = exeLogDao.searchByTid(table_id);
		zTablePanel.reloadData(list);
		log.info("end in load execution log information for table ...");
	}
	
	@Override
	public String getMessage() {
		// TODO Auto-generated method stub
		return "load execution log information of table in detail ...";
	}

	@Override
	public void handle() {
		// TODO Auto-generated method stub
		loadData();
	}
	
	public int getTable_id() {
		return table_id;
	}

	public void setTable_id(int tableId) {
		table_id = tableId;
	}

}
